import { HttpException, HttpStatus, ValidationPipe, ValidationPipeOptions } from "@nestjs/common";

export default function dtoValidationPipe(params:ValidationPipeOptions = {}) {
    return new ValidationPipe({
        stopAtFirstError : true,
        whitelist : true,
        transform : true,
        exceptionFactory : (errors) => {
            const constraints = errors[0].constraints
            const keys = Object.keys(constraints)
            throw new HttpException(constraints[keys[0]], HttpStatus.FORBIDDEN);
        },

        ...params
    })
}